package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.service.UploadService;
import cn.tedu.eb_film.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @author ライナー・ロンテ
 * @since 2023/3/18 12:38
 */
@RestController
@Slf4j
@Api(tags = "文件上传模块")
public class UploadController {
    @Autowired
    private UploadService uploadService;

    @RequestMapping("/upload")
    public JsonResult<String> uploadFile(MultipartFile file) {
        /*
          将这个upload路径存入到数据库
         */
        final String upload = uploadService.upload(file);
        if (upload == null) {
            return null;
        }
        System.out.println("upload:"+upload);
        return JsonResult.ok(upload);
    }
}
